package com.tvsinfo.jdk.demo.case2_function_interface.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 订单类型枚举
 *
 * @Author qiyi
 * @Date 2018/6/4
 */
public enum OrderTypeEnum {
    DINNER(101, "点餐-正餐", 1, "正餐", 1),
    FAST_MEAL_QUE(102, "点餐-快餐-排队取餐", 1, "快餐", 2),
    FAST_MEAL_DESK(103, "点餐-快餐-桌台取餐", 1, "快餐", 2),

    TAKE_OUT_ORDER(201, "外卖-商户配送", 2, "外卖", 3),
    TAKE_OUT_ORDER_PICK(202, "外卖-用户自提", 2, "外卖", 4),


    POINT_MALL_ORDER_REAL(1001, "积分商城-实物", 9, "积分商城",null),
    POINT_MALL_ORDER_CARD(1002, "积分商城-卡券", 9, "积分商城",null),


    ;

    OrderTypeEnum(Integer key, String desc, Integer oldType, String oldDesc, Integer oldSubType) {
        this.key = key;
        this.desc = desc;
        this.oldDesc = oldDesc;
        this.oldSubType = oldSubType;
        this.oldType = oldType;
    }

    private static final Map<Integer, OrderTypeEnum> orderTypeEnumMap = new ConcurrentHashMap<>();
    private static final Map<Integer, List<OrderTypeEnum>> oldOrderTypeEnumMap = new ConcurrentHashMap<>();
    private Integer key;
    private String desc;
    private String oldDesc;
    private Integer oldType;
    private Integer oldSubType;

    static {
        OrderTypeEnum[] arr$ = values();
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            OrderTypeEnum orderType = arr$[i$];
            orderTypeEnumMap.put(orderType.getKey(), orderType);

            List<OrderTypeEnum> orderStatusEnums = oldOrderTypeEnumMap.get(orderType.getOldType());
            if (null == orderStatusEnums) {
                orderStatusEnums = new ArrayList<>();
                oldOrderTypeEnumMap.put(orderType.getOldType(), orderStatusEnums);
            }
            orderStatusEnums.add(orderType);
        }
    }

    public static Integer getByKey(Integer code) {
        if (null == code) {
            return null;
        }
        return orderTypeEnumMap.get(code).getKey();
    }

    /**
     * 根据老的type获取新的type
     * create by Ruyi.Song on 2018/8/16 15:36
     */
    public static List<OrderTypeEnum> getByOldType(Integer oldType) {
        if (null == oldType) {
            return null;
        }
        List<OrderTypeEnum> orderTypeEnum = oldOrderTypeEnumMap.get(oldType);
        return orderTypeEnum;
    }

    public Integer getKey() {
        return this.key;
    }

    public Integer getOldType() {
        return this.oldType;
    }

    public Integer getOldSubType() {
        return this.oldSubType;
    }

    public String getDescription() {
        return this.desc;
    }

    public String getOldDesc() {
        return oldDesc;
    }



}
